package com.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.cells.License;
import com.aspose.cells.PdfSaveOptions;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

/**
 * aspose for pdf
 * 
 * 
 * 最新完美破解版，无水印无文件大小限制，无使用时间限制<br>
 * 由于aspose比较吃内存，操作大一点的文件就会堆溢出，所以请先设置好java虚拟机参数：-Xms1024m -Xmx1024m(参考值)<br>
 * 如果亲们在使用过程中有任何问题，请在CSDN下载界面留言，或者联系QQ群931233662询问<br>
 * 本人亲自破解，内含Eclipse工程，直接导入Eclipse就能运行该demo<br>
 * 
 * 适用于jdk6.0的环境，免费使用！<br>
 * 
 * ======警告：请勿用于商业用途，仅供学习研究使用，如有任何版权纠纷，本人概不负责！=====<br>
 * 
 * @author Aspose
 *
 */
public class TestCells {

	private static InputStream license;
	private static InputStream fileInput;
	private static File outputFile;

	/**
	 * 获取license
	 * 
	 * @return
	 */
	public static boolean getLicense() {
		boolean result = false;
		try {
			ClassLoader loader = Thread.currentThread().getContextClassLoader();
			license = new FileInputStream(loader.getResource("license.xml").getPath());// 凭证文件
			fileInput = new FileInputStream(loader.getResource("abc.xlsx").getPath());// 待处理的文件
			outputFile = new File("D:/abc11.pdf");// 输出路径

			License aposeLic = new License();
			aposeLic.setLicense(license);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// 验证License
		if (!getLicense()) {
			return;
		}
		try {
			long old = System.currentTimeMillis();
			 Workbook wb = new Workbook(fileInput);
			   Worksheet ws = wb.getWorksheets().get(0);
			   PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
			//   pdfSaveOptions.setOnePagePerSheet(true);
			   pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
			   FileOutputStream fileOS = new FileOutputStream(outputFile);
			   ws.getHorizontalPageBreaks().clear();
			   ws.getVerticalPageBreaks().clear();
			   wb.save(fileOS, pdfSaveOptions);
			   fileOS.close();
			long now = System.currentTimeMillis();
			System.out.println("共耗时：" + ((now - old) / 1000.0) + "秒\n\n" + "文件保存在:" + outputFile.getPath());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}